package com.google.code.b0rx0r.advancedSamplerEngine;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class ChannelOutputMap implements Serializable {
	private static final long serialVersionUID = "ChannelOutputMap 1.0".hashCode(); //$NON-NLS-1$
	
	private Map<Integer, Set<Integer>> channelsToOutputs = new HashMap<Integer, Set<Integer>>();
	
	public void addMapping(int channel, int output) {
		Set<Integer> set = channelsToOutputs.get(channel);
		
		if (set == null) {
			set = new HashSet<Integer>();
			channelsToOutputs.put(channel, set);
		}
		
		set.add(output);
	}
	
	public void removeMapping(int channel, int output) {
		Set<Integer> set = channelsToOutputs.get(channel);
		
		if (set != null) {
			set.remove(output);
		}
		
	}
	
	public Set<Integer> getOutputs(int channel) {
		Set<Integer> set = channelsToOutputs.get(channel);
		
		if (set != null)
			return set;
		else
			return Collections.<Integer>emptySet();
		
		
		
	}

	public void copyFrom(ChannelOutputMap source) {
		for (int channel : source.channelsToOutputs.keySet()) {
			for (int output : source.getOutputs(channel)) {
				addMapping(channel, output);
			}
		}
	}

}
